package com.lou1052.redis.config;

import java.util.Objects;

/**
 * Redis 节点 连接信息
 * Created with IntelliJ IDEA.
 * User: liuqing
 * Date: 2015/9/27
 * Time: 21:52
 * To change this template use File | Settings | File Templates.
 */
public class NodeInfo {
    private String ip;

    private int port;
    /**
     * 是否验证密码
     */
    private boolean needAuth;

    /**
     * 密码
     */
    private String auth;

    /**
     * 分片时的名称
     */
    private String name;

    /**
     * 分片时节点权重 默认1
     */
    private int weight=1;

    public NodeInfo(String ip, int port, boolean needAuth, String auth) {
        this.ip = ip;
        this.port = port;
        this.needAuth = needAuth;
        this.auth = auth;
    }

    /**
     * @param needAuth 是否验证密码
     * @param auth 密码
     * @param ip
     * @param port
     * @param name  节点名称
     * @param weight 节点权重
     */
    public NodeInfo( String ip, int port,boolean needAuth,String auth,String name, int weight) {
        this.needAuth=needAuth;
        this.auth = auth;
        this.ip = ip;
        this.name = name;
        this.port = port;
        this.weight = weight;
    }

    public NodeInfo(){}

    /**
     * Getter for property 'ip'.
     *
     * @return Value for property 'ip'.
     */
    public String getIp() {
        return ip;
    }

    /**
     * Setter for property 'ip'.
     *
     * @param ip Value to set for property 'ip'.
     */
    public void setIp(String ip) {
        this.ip = ip;
    }

    /**
     * Getter for property 'port'.
     *
     * @return Value for property 'port'.
     */
    public int getPort() {
        return port;
    }

    /**
     * Setter for property 'port'.
     *
     * @param port Value to set for property 'port'.
     */
    public void setPort(int port) {
        this.port = port;
    }

    /**
     * Getter for property 'needAuth'.
     *
     * @return Value for property 'needAuth'.
     */
    public boolean isNeedAuth() {
        return needAuth;
    }

    /**
     * Setter for property 'needAuth'.
     *
     * @param needAuth Value to set for property 'needAuth'.
     */
    public void setNeedAuth(boolean needAuth) {
        this.needAuth = needAuth;
    }

    /**
     * Getter for property 'auth'.
     *
     * @return Value for property 'auth'.
     */
    public String getAuth() {
        return auth;
    }

    /**
     * Setter for property 'auth'.
     *
     * @param auth Value to set for property 'auth'.
     */
    public void setAuth(String auth) {
        this.auth = auth;
    }

    /**
     * Getter for property 'name'.
     *
     * @return Value for property 'name'.
     */
    public String getName() {
        return name;
    }

    /**
     * Setter for property 'name'.
     *
     * @param name Value to set for property 'name'.
     */
    public void setName(String name) {
        this.name = name;
    }

    /**
     * Getter for property 'weight'.
     *
     * @return Value for property 'weight'.
     */
    public int getWeight() {
        return weight;
    }

    /**
     * Setter for property 'weight'.
     *
     * @param weight Value to set for property 'weight'.
     */
    public void setWeight(int weight) {
        this.weight = weight;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;
        NodeInfo nodeInfo = (NodeInfo) o;
        return Objects.equals(port, nodeInfo.port) &&
                Objects.equals(ip, nodeInfo.ip);
    }

    @Override
    public int hashCode() {
        return Objects.hash(ip, port);
    }
}
